'use strict';
// 获取数据库的引用
const db = uniCloud.database();
// 获取集合的引用
const shopListCollection = db.collection('shopList');

exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	let dbData = await shopListCollection.get()
	console.log('------', dbData.data)
	const newArr = dbData.data.filter(dItem => dItem.shopCode === event.shopCode)
	let res
	if (newArr.length === 0) {
		// 新增数据
		res = await shopListCollection.add(event)
	} else {
		res = {
			res_code:0,
			res_message:'已存在商品'
		}
	}
	//返回数据给客户端
	return res
};
